package com.socket.transfer_file;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @ClassName: FileServer
 * @Author: ZhangYue26
 * @Description: 传输文件服务端
 * @Date: 2020-10-09
 */
public class FileServer {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8569);
        Socket accept = serverSocket.accept();
        InputStream inputStream = accept.getInputStream();
        FileOutputStream fileOutputStream = new FileOutputStream(new File("C:\\Users\\zhangyue26\\Desktop\\lfasr-sdk-3.0.0.jar"));
        byte[] bytes = new byte[8 * 1024];
        while (inputStream.read(bytes) != -1) {
            fileOutputStream.write(bytes);
            fileOutputStream.flush();
        }
        fileOutputStream.close();
        System.out.println("服务端接收文件完毕！！");
    }
}
